package q_2020_12

import (
	"fmt"
	"strconv"
)

// 旋转数字
func rotateNum(num int) {
	if num <= 0 {
		return
	}

	var arr = [][]int{}
	for i := 0; i < num; i++ {
		arr = append(arr, make([]int, num))
	}
	index := 1
	value := 1

	for index <= (num/2 + num%2) {
		offset := index - 1
		// 每次走 一圈
		top := arr[offset]
		i := offset
		for i < num-offset {
			top[i] = value
			i++
			value++
		}

		// 右边
		i = index
		for i < num-offset {
			t := num - 1 - offset
			arr[i][t] = value
			i++
			value++
		}
		// 下方 逆向
		i = num - offset - 1
		bottom := arr[i]
		i--
		for i >= offset {
			bottom[i] = value
			value++
			i--
		}

		// 左边 逆向
		i = (num - 1) - offset - 1
		for i > offset {
			arr[i][offset] = value
			i--
			value++
		}

		index++

		i = 0
	}

	// 打印数字
	for _, ints := range arr {
		strs := []string{}
		for _, i2 := range ints {
			strs = append(strs, strconv.FormatInt(int64(i2), 10))
		}
		for _, str := range strs {
			fmt.Print(fmt.Sprintf("%4s,", str))
		}
		fmt.Println()

	}

	println("完成")
}
